<template>
  <div class="routine_container">
    <div class="title">业务系统实时数据监控列表</div>

    <Card class="query">
      <div class="query_content">
        <div>
          <span>分组展示：</span>
          <Select
            v-model:value="query.group"
            mode="multiple"
            style="width: 260px"
            :max-tag-count="1"
            :options="options"
          ></Select>
        </div>
        <div>
          <Button type="primary" ghost @click="onReset">重置</Button>
        </div>
      </div>
    </Card>

    <Card class="card_content">
      <div class="card_container">
        <div class="flow server" v-for="item in 3">
          <div class="top">
            <span>流服务器</span>
            <span>101.43.172.43</span>
          </div>
          <div class="bottom">
            <Row>
              <Col :span="4">
                <div class="bottom_item">
                  <div>
                    <UserOutlined />
                    <span class="span label">在线用户</span>
                  </div>
                  <span v-for="item in 3" class="span">Root</span>
                </div>
              </Col>
              <Col :span="4">
                <div class="bottom_item">
                  <div>
                    <UserOutlined />
                    <span class="span label">当前队列数据流量</span>
                  </div>
                  <span v-for="item in 3" class="span">21.2kb</span>
                </div>
              </Col>
              <Col :span="4">
                <div class="bottom_item">
                  <div>
                    <UserOutlined />
                    <span class="span label">平均队列数据数量(1min)</span>
                  </div>
                  <span v-for="item in 3" class="orange span">21.2kb</span>
                </div>
              </Col>
              <Col :span="4">
                <div class="bottom_item">
                  <div>
                    <UserOutlined />
                    <span class="span label">平均队列数据数量(5min)</span>
                  </div>
                  <span v-for="item in 3" class="orange span">21.2kb</span>
                </div>
              </Col>
              <Col :span="4">
                <div class="bottom_item">
                  <div>
                    <UserOutlined />
                    <span class="span label">平均队列数据数量(15min)</span>
                  </div>
                  <span v-for="item in 3" class="orange span">21.2kb</span>
                </div>
              </Col>
              <Col :span="4">
                <div class="bottom_item">
                  <div>
                    <UserOutlined />
                    <span class="span label">数据延迟(s)</span>
                  </div>
                  <span v-for="item in 3" class="span">0</span>
                </div>
              </Col>
            </Row>
          </div>
        </div>
        <div class="aws server" v-for="item in 3">
          <div class="top">
            <span>AWS服务器</span>
            <span>101.43.172.43</span>
          </div>
          <div class="bottom">
            <div class="item">
              <Row>
                <Col :span="10">磁盘空间使用率</Col>
                <Col :span="4">
                  <AreaChartOutlined />
                </Col>
                <Col :span="10">
                  <div class="progress">
                    <Progress
                      :percent="57"
                      :size="[300, 20]"
                      :show-info="false"
                      strokeLinecap="butt"
                      :strokeColor="strokeColor(57)"
                    >
                    </Progress>
                    <div class="info" :style="customStyle(57)">57%</div>
                  </div>
                </Col>
              </Row>
            </div>
            <div class="item">
              <Row>
                <Col :span="10">波形存储空间总量</Col>
                <Col :span="4">
                  <PieChartOutlined />
                </Col>
                <Col :span="10">29 G</Col>
              </Row>
            </div>
            <div class="item">
              <Row>
                <Col :span="10">索引总量</Col>
                <Col :span="4">
                  <BranchesOutlined />
                </Col>
                <Col :span="10">11 Mb</Col>
              </Row>
            </div>
          </div>
        </div>
        <div class="aws server" v-for="item in 3">
          <div class="top">
            <span>RTS服务器</span>
            <span>101.43.172.43</span>
          </div>
          <div class="bottom">
            <div class="item">
              <Row>
                <Col :span="14">关键日志监控状态</Col>
                <Col :span="10">
                  <span>监控中</span>
                  <CheckOutlined class="success icon" />
                </Col>
              </Row>
            </div>
          </div>
        </div>

        <div class="aws server" v-for="item in 3">
          <div class="top">
            <span>RTS服务器</span>
            <span>101.43.172.43</span>
          </div>
          <div class="bottom">
            <div class="item">
              <Row>
                <Col :span="14">关键日志监控状态</Col>
                <Col :span="10">
                  <span>监控中</span>
                  <CloseOutlined class="error icon" />
                </Col>
              </Row>
            </div>
          </div>
        </div>
      </div>
    </Card>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import {
  AreaChartOutlined,
  BranchesOutlined,
  CheckOutlined,
  CloseOutlined,
  PieChartOutlined,
  UserOutlined,
} from '@ant-design/icons-vue';
import { Button, Card, Col, Progress, Row, Select } from 'ant-design-vue';

const options = ref([
  {
    label: '流服务器',
    value: 1,
  },
  {
    label: '波形存储',
    value: 2,
  },
  {
    label: '地震预警',
    value: 3,
  },
]);
const query = ref({
  group: [1, 2],
});

const onReset = () => {
  query.value.group = [1, 2, 3];
};

const strokeColor = (val) => {
  if (val <= 30) {
    return '#52c41a';
  } else if (val <= 50) {
    return '#165dff';
  } else if (val <= 70) {
    return '#f4d07b';
  } else {
    return '#ff0f0f';
  }
};

const customStyle = (val) => {
  return {
    left: `calc(${val}% - 40px)`,
  };
};
</script>

<style scoped lang="scss">
.query_content {
  display: flex;
  justify-content: space-between;
}
.routine_container {
  height: 100%;
  .title {
    padding: 15px 0;
    font-weight: 700;
  }
  .query {
    margin-bottom: 15px;
  }
  .card_content {
    height: calc(100% - 145px);
    overflow-y: auto;
    .card_container {
      display: flex;
      justify-content: space-between;
      flex-wrap: wrap;
      .server {
        margin-bottom: 25px;
        border: 1px solid #ccc;
        border-radius: 8px;
        .top {
          border-bottom: 1px solid #ccc;
          padding: 4px 25px;
          span {
            &:first-child {
              margin-right: 10px;
            }
          }
        }
        .bottom {
          padding: 8px 25px;
          &_item {
            display: flex;
            flex-direction: column;
            .span {
              padding: 0 10px;
              margin: 12px 0 0 12px;
              border-radius: 4px;
              width: fit-content;

              &.orange {
                font-weight: 700;
                background-color: #f0951f;
              }
              &.label {
                margin: 0;
              }
            }
          }
          .item {
            margin-bottom: 15px;
            &:last-child {
              margin: 0;
            }
            :deep(.ant-progress-inner) {
              border-radius: 0;
              border: 1px solid #ccc;
            }
            .progress {
              position: relative;
              .info {
                position: absolute;
                top: 2px;
                color: #000;
              }
            }
            .icon {
              margin-left: 20px;
              border-radius: 50%;
              font-size: 12px;
              padding: 3px;
              &.success {
                background-color: green;
              }
              &.error {
                background-color: red;
              }
            }
          }
        }
        &.flow {
          width: 100%;
        }
        &.aws {
          width: 32%;
        }
      }
    }
  }
}
</style>

<route lang="json">
{
  "meta": {
    "title": "业务监控"
  }
}
</route>
